﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SzCourt.Logic.BLL;

namespace SzCourt.WebSite.lian
{
    public partial class result : System.Web.UI.Page
    {
        private string _ClassName = string.Empty;
        private string _Password = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                getParam();
                getInfo();
            }
        }

        //获取参数值
        private void getParam()
        {
            this._ClassName = string.IsNullOrEmpty(Request.Form["txtClassName"]) ? "" : Request.Form["txtClassName"];           
            this._Password = string.IsNullOrEmpty(Request.Form["txtPassword"]) ? "" : Request.Form["txtPassword"];
            if (this._ClassName.Length < 1 || this._Password.Length < 1)
            {
                Response.Redirect("/lian/search.aspx");
            }
        }

        /// <summary>
        /// 获取基本信息
        /// </summary>
        private void getInfo()
        {
            PreCase bll = new PreCase();
            PreCaseParam param = new PreCaseParam();
            param.PreCaseSerial = _ClassName;
            param.QueryPWD = this._Password;
            PreQueryResult result = (PreQueryResult)bll.QueryPreCaseInfo(param);

            if (result != null && result.PreCaseInfo!=null)
            {
                this.tdAddDateTime.InnerHtml = result.AddDateTime.ToShortDateString() + "&nbsp;";
                this.tdAppointmentDate.InnerHtml = result.AppointmentDate.ToShortDateString()+"&nbsp;";
                this.tdAutoReplyContent.InnerHtml = result.AutoReplyContent + "&nbsp;";
                this.tdHandleStatusName.InnerHtml = result.HandleStatusName + "&nbsp;";//状态
                this.tdPreCaseSerial.InnerHtml = result.PreCaseSerial + "&nbsp;";
                this.tdCauseOfAction.InnerHtml = result.PreCaseInfo.CauseOfAction;
                this.tdReplyContent.InnerHtml = result.PreCaseInfo.ReplyContent + "&nbsp;";

                //this.hdnPreCaseInfoID.Value = result.PreCaseInfo.PreCaseInfoID.ToString();
                this.tdPreCaseSerial.InnerHtml = result.PreCaseInfo.PreCaseSerial;
                this.tdEmail.InnerHtml = result.PreCaseInfo.Email;
                this.tdPhone.InnerHtml = result.PreCaseInfo.Phone;
                this.tdStartingMark.InnerHtml = result.PreCaseInfo.StartingMark.HasValue ? result.PreCaseInfo.StartingMark.ToString(): "";
                switch (result.PreCaseInfo.PreCaseType)
                {
                    case 1:
                        this.tdPreCaseType.InnerHtml = "民事案件";
                        break;
                    case 2:
                        this.tdPreCaseType.InnerHtml = "商事案件";
                        break;
                    default:
                        this.tdPreCaseType.InnerHtml = "执行案件";
                        break;
                }
                //this.tdHandleStatus.InnerHtml = result.PreCaseInfo.Audited == 1 ? "已处理" : result.PreCaseInfo.HandleStatus == 0 ? "未处理" : "已处理";
                //this.tdAddDateTime.InnerHtml = result.PreCaseInfo.AddDateTime.ToString();
                //this.tdAudited.InnerHtml = result.PreCaseInfo.Audited == 0 ? "未审核" : "已审核";
                //
                //this.tdReplyContent.Value = result.PreCaseInfo.ReplyContent;

                //原告
                this.Repeater1.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 1 && a.PartiesType == 0).ToList();
                this.Repeater1.DataBind();
                this.Repeater2.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 2 && a.PartiesType == 0).ToList();
                this.Repeater2.DataBind();
                this.Repeater3.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 3 && a.PartiesType == 0).ToList();
                this.Repeater3.DataBind();

                //被告
                this.Repeater4.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 1 && a.PartiesType == 1).ToList();
                this.Repeater4.DataBind();
                this.Repeater5.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 2 && a.PartiesType == 1).ToList();
                this.Repeater5.DataBind();
                this.Repeater6.DataSource = result.PrePartiesList.Where(a => a.PartiesClass == 3 && a.PartiesType == 1).ToList();
                this.Repeater6.DataBind();

                //证据文件
                if (result.PreCaseFile != null && result.PreCaseFile.Count() > 0)
                {
                    this.rptFile.Visible = true;
                    this.rptFile.DataSource = result.PreCaseFile;
                    this.rptFile.DataBind();
                }
            }
            else 
            { 
                this.nodata.Attributes.Add("class", ""); 
                this.tblResult.Attributes.Add("class", "tbl g_dn");
            }
  

        }
    }
}